
$.extend($.validator.methods, { webService: function(value, element, param) {
    if (this.optional(element))
        return "dependency-mismatch";

    var previous = this.previousValue(element);
    if (!this.settings.messages[element.name])
        this.settings.messages[element.name] = {};
    previous.originalMessage = this.settings.messages[element.name].webService;
    this.settings.messages[element.name].webService = previous.message;

    param = typeof param == "string" && { url: param} || param;

    if (previous.old !== value) {
        previous.old = value;
        var validator = this;
        this.startRequest(element);
        var data = {};
        data[param.webserviceParaName] = value;
        $.ajax($.extend(true, {
            url: param,
            mode: "abort",
            port: "validate" + element.name,
            dataType: "json",
            data: $.toJSON(data),
            success: function(response) {
                response = response.d;
                validator.settings.messages[element.name].webService = previous.originalMessage;
                var valid = response === true;
                if (valid) {
                    var submitted = validator.formSubmitted;
                    validator.prepareElement(element);
                    validator.formSubmitted = submitted;
                    validator.successList.push(element);
                    validator.showErrors();
                } else {
                    var errors = {};
                    var message = (previous.message = response || validator.defaultMessage(element, "webService"));
                    errors[element.name] = $.isFunction(message) ? message(value) : message;
                    validator.showErrors(errors);
                }
                previous.valid = valid;
                validator.stopRequest(element, valid);
            },
            error: function(xmlHttpRequest, textstatus, errorthrown) {
                if (textstatus == 'timeout') {
                    alert('网络连接故障，服务器响应超时！');
                    return;
                }
                console.log(xmlHttpRequest);
            }

        }, param));
        return "pending";
    } else if (this.pending[element.name]) {
        return "pending";
    }
    return previous.valid;
}
});
